#include "../begonia.h"
#include "../base/scene.h"

void drawcircle(double x,double y,double r)
{
    glPushMatrix();
        glTranslated(x,y,0.0);
        glBegin(GL_POLYGON);
            for(int i=0;i<=slices;i++)
            {
                glVertex2d(r*cos(M_PI*2.0*i/slices),r*sin(M_PI*2.0*i/slices));
            }
        glEnd();
    glPopMatrix();
}

void drawcircle2(double x,double y,double r)
{
    glPushMatrix();
        glTranslated(x,y,0.0);
        glBegin(GL_LINE_LOOP);
            for(int i=0;i<slices;i++)
            {
                glVertex2d(r*cos(M_PI*2.0*i/slices),r*sin(M_PI*2.0*i/slices));
            }
        glEnd();
    glPopMatrix();
}

void drawstring(double x,double y,const char* str,double offset)
{
    int chpos;
    if(offset>0.0)
    {
        chpos=0;
        for(int i=0;str[i];i++) chpos += glutBitmapWidth(GLUT_BITMAP_9_BY_15, str[i]);
        x-=offset*chpos;
    }
    chpos=0;
    glPushMatrix();
        glTranslated(x,y,0.0);
        for(int i=0;str[i];i++) {
            glRasterPos2d(chpos,0.0);
            glutBitmapCharacter(GLUT_BITMAP_9_BY_15, str[i]);
            chpos += glutBitmapWidth(GLUT_BITMAP_9_BY_15, str[i]);
        }
    glPopMatrix();
}

void drawJiki()
{
     glBegin(GL_LINES);
        glVertex2d(fbx-fbw/2.0,fby-fbh/2.0);glVertex2d(fbx-fbw/2.0+fbk,fby-fbh/2.0);
        glVertex2d(fbx-fbw/2.0,fby-fbh/2.0);glVertex2d(fbx-fbw/2.0,fby-fbh/2.0+fbk);
        glVertex2d(fbx+fbw/2.0,fby-fbh/2.0);glVertex2d(fbx+fbw/2.0-fbk,fby-fbh/2.0);
        glVertex2d(fbx+fbw/2.0,fby-fbh/2.0);glVertex2d(fbx+fbw/2.0,fby-fbh/2.0+fbk);
        glVertex2d(fbx+fbw/2.0,fby+fbh/2.0);glVertex2d(fbx+fbw/2.0-fbk,fby+fbh/2.0);
        glVertex2d(fbx+fbw/2.0,fby+fbh/2.0);glVertex2d(fbx+fbw/2.0,fby+fbh/2.0-fbk);
        glVertex2d(fbx-fbw/2.0,fby+fbh/2.0);glVertex2d(fbx-fbw/2.0+fbk,fby+fbh/2.0);
        glVertex2d(fbx-fbw/2.0,fby+fbh/2.0);glVertex2d(fbx-fbw/2.0,fby+fbh/2.0-fbk);
        glVertex2d(fbx-fcw/2.0,fby);glVertex2d(fbx+fcw/2.0,fby);
        glVertex2d(fbx,fby-fch/2.0);glVertex2d(fbx,fby+fch/2.0);
    glEnd();
    if(corer>0.0)
    {
        glColor3d(1.0,1.0,1.0);
        drawcircle(corex,corey,corer);
        glColor3d(1.0,0.0,0.0);
        drawcircle2(corex,corey,corer);
    }
    if(shooting)
    {
        glColor4d(0.0,0.0,0.0,0.5);
        glPushMatrix();
            glTranslated(cbx,cby,0.0);
            glBegin(GL_TRIANGLE_STRIP);
                glVertex2d(-dLarge,-dLarge);
                glVertex2d(-cbw/2.0,-cbh/2.0);
                glVertex2d(dLarge,-dLarge);
                glVertex2d(cbw/2.0,-cbh/2.0);
                glVertex2d(dLarge,dLarge);
                glVertex2d(cbw/2.0,cbh/2.0);
                glVertex2d(-dLarge,dLarge);
                glVertex2d(-cbw/2.0,cbh/2.0);
                glVertex2d(-dLarge,-dLarge);
                glVertex2d(-cbw/2.0,-cbh/2.0);
            glEnd();
        glPopMatrix();
    }
}

void drawFPS()
{
    char s[64];
    glColor3d(1.0,1.0,1.0);
    drawstring(0.0,sch-16.0,tests);
    sprintf(s,"%.1ffps",realfps);
    glColor3d(1.0,1.0,1.0);
    drawstring(scw,0.0,s,1.0);
}

void drawPictures()
{
    for(int i=0;i<picn;i++)
    {
        pic[i].show();
	}
}
 
void drawPercentage()
{
 char s[64];
 sprintf(s,"%d%%",(int)per);
 glColor3d(1.0,1.0,1.0);
 drawstring(f.px,f.py+20.0,s,0.5);//tomo
}
